package com.example.demo2302.service;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class AspectJByAno {

    @Pointcut("execution(* com.example.demo2302.service.*.*(..))")
    public void pointCut(){

    }

    @Before("pointCut()")
    public void myBefore(JoinPoint joinPoint) {
        System.out.println("前置通知执行=====");
        System.out.println("目标类：" + joinPoint.getTarget());
        System.out.println("增强的目标方法:" + joinPoint.getSignature().getName());
    }

    @Around("pointCut()")
    public Object myAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕通知开始=======");
        Object obj = proceedingJoinPoint.proceed();
        System.out.println("环绕通知结束---------");
        return obj;
    }

    @AfterReturning("pointCut()")
    public void myAfterReturn(JoinPoint joinPoint) {
        System.out.println("后置返回通知=====");
    }
    @After("pointCut()")
    public void myAfter(JoinPoint joinPoint) {
        System.out.println("后置最终通知====");
    }

    @AfterThrowing(value = "pointCut()",throwing = "e")
    public void myThrowing(JoinPoint joinPoint,Throwable e){
        System.out.println("异常通知====");
        System.out.println(e.getMessage());
    }



}
